'''
Created on Oct 25, 2009

@author: Owner
'''
import gamephase.game_phase as GP
import utility as U
import global_controller as gc
import gamephase.humanVsHuman as hVh
import gamephase.computerVsComputer as cVc
import gamephase.trainer as trainer

class MainMenu(GP.GamePhase):
    '''
    classdocs
    '''
    menu_items = ['Human Vs Human', 'Computer Vs Computer', 'Train Computer', 'MINI-GAME', 'Quit Game',\
				]
    menu_item_shown = 0
    menu_showned = False
    key_code = 0
    
    def __init__(self):
        '''
        Constructor
        '''
        
    def execute(self):
        if not MainMenu.menu_showned :
            self.print_menu()
            MainMenu.menu_showned = True

        MainMenu.key_code = U.kbfunc()
        
        if MainMenu.key_code == 72 and MainMenu.menu_item_shown > 1 : # Up
            MainMenu.menu_item_shown -= 1
            MainMenu.menu_showned = False
        if MainMenu.key_code == 80 \
            and MainMenu.menu_item_shown < 4: # Down
            MainMenu.menu_item_shown += 1
            MainMenu.menu_showned = False
        
        if MainMenu.key_code == 13:
            if MainMenu.menu_item_shown == 5:
                gc.G.game_phase = GP.GamePhaseEnd()
            elif MainMenu.menu_item_shown == 4:
                gc.G.game_phase = GP.GamePhaseWonder()
            elif MainMenu.menu_item_shown == 2:
                gc.G.game_phase = cVc.ComputerVsComputer()
            elif MainMenu.menu_item_shown == 1:
                gc.G.game_phase = hVh.HumanVsHuman()
            elif MainMenu.menu_item_shown == 3:
                gc.G.game_phase = trainer.Trainer()
    
    def print_menu(self):
        U.clear_screen()
        
        for i in range(len(MainMenu.menu_items)):
            j = i + 1
            order = j if j != MainMenu.menu_item_shown else '*'
            print("{0:>2}. {1}".format(order, MainMenu.menu_items[i]))
            
#        print("Debug M:{0} K:{1}".format(MainMenu.menu_item_shown, MainMenu.key_code))
        pass